package com.cx.androidtools;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class CustomDialogActivity extends Activity implements OnClickListener {
	private Button btn_01;
	private AlertDialog.Builder dialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.custom_dialog_layout);
		btn_01 = (Button) findViewById(R.id.button1);
		btn_01.setOnClickListener(this);
	}

	private void ShowAlertDialog() {
		// new AlertDialog.Builder(this).setTitle("请输入")
		// .setIcon(android.R.drawable.ic_dialog_info)
		// .setView(new EditText(this)).setPositiveButton("确定", null)
		// .setNegativeButton("取消", null).show();
		// if (dialog == null) {
		dialog = new AlertDialog.Builder(this);
		// LayoutInflater mInflater = LayoutInflater.from(this);
		// View view = mInflater.inflate(R.layout.dialog_layout, null);
		View view = null;
		if (view == null) {
			LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
			view = inflater.inflate(R.layout.dialog_layout, null);
		}
		// dialog.setView(LayoutInflater.from(this).inflate(
		// R.layout.dialog_layout, null));
		dialog.setView(view);
		dialog.setNegativeButton("取消", null);
		dialog.setPositiveButton("确定", null);
		dialog.create();
		// }
		dialog.show();
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.button1:
			// dialog.show();
			ShowAlertDialog();
			break;

		default:
			break;
		}

	}
}
